/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2025/6/17
 * Time: 22:35
 */

#include "Effect.h"
#include "../core/scene.h"

Effect * Effect::AddEffectChild(Object * _parent, const std::string & _file_path, glm::vec2 _pos, float _scale, ObjectWorld * _next_object)
{
    auto effect = new Effect();
    effect->Init();
    effect->sprite_ = SpriteAnim::AddSpriteAnimChild(effect, _file_path, _scale);
    effect->sprite_->SetLoop(false);
    effect->SetPosition(_pos);
    effect->SetNextObject(_next_object);

    if(nullptr != _parent)
        _parent->AddChild(effect);
    return effect;
}

void Effect::Update(float _dt)
{
    ObjectWorld::Update(_dt);
    CheckFinish();
}

void Effect::CheckFinish()
{
    if (sprite_->IsFinish())
    {
        need_remove_ = true;
        if (nullptr != next_object_){
            game_.GetCurrentScene()->SafeAddChild(next_object_);
        }
    }
}